#ifndef TEXTTRANSLATOR_H
#define TEXTTRANSLATOR_H

#include "define.h"
#include "setting.h"

#include <QNetworkAccessManager>

class TextTranslator : public QNetworkAccessManager {
    Q_OBJECT

public:
    struct RequestContent {
        QString address = ADDRESS_TRANSLATE;
        QString textToTranslate;
        QString from;
        QString to;
        QString appid = SETTING.getAppId();
        QString salt;
        QString sign;
        QString pwd = SETTING.getSecretKey();
    };

public:
    TextTranslator(QObject* parent = nullptr);

    void translate(const QString& textToTranslate, Language from, Language to);

signals:
    void translateResult(const QString& result);

private:
    void onReply(QNetworkReply* reply);
    QString stringToSignFromContent();
    QString resultInReply(const QByteArray& replyBytes);

private:
    RequestContent m_content;
};

#endif // TEXTTRANSLATOR_H
